PHP新手30天實戰金流
, Laravel6
bootstrap/app.php
中<?php
/*
| Create The Application
*/
$app = new Illuminate\Foundation\Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);
/*
| Bind Important Interfaces
*/
$app->singleton(
Illuminate\Contracts\Http\Kernel::class,
App\Http\Kernel::class
);
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
return $app;
<?php
$containter = require('Container');
// 建立抽象與實體類別的對應
$containter->bind(ILogService, AWSLogServcie::class);
$log = $container->make(Log::class);
$log->send('log....');
App::bind('UserRepository', function()
{
return new AWSUserRepository;
});
App::bind('UserRepositoryInterface', 'DbUserRepository');
APP::bind('UserRepository')
App::singleton('UserRepository', function()
{
return new AWSUserRepository;
});
<?php
$app->make('UserRepository');
若都在同一支 bootstrap/app.php
註冊,多人開發時,會一直有 merge conflict
實際執行 service proivder 的方法在 ProviderRepository
中。主要流程如下:
資料來源:
阿... 還有好多不懂的地方..內容會再追加補充><
晚生學習分享所學經驗,若內容有誤或不清楚,煩請不吝指教!更是歡迎各位大神多多補充,感謝萬分!